/**
 * @author : andy
 * @description : stomp客户端
 */
import ClientManager from "../utils/manager";
import Stomp, { type StompParams } from "./stomp";
export default class StompClient {
  private manager: ClientManager<Stomp>;
  constructor () {
    this.manager = new ClientManager();
  }
  create (options: StompParams) {
    const stomp = new Stomp(options);
    this.manager.add(stomp);
    return this.manager.get(stomp.id) as Stomp;
  }
  delete (stomp: Stomp) {
    this._delete(stomp.id);
    stomp.disconnect();
  }
  private _delete (id: string) {
    this.manager.delete(id);
  }
  get (id: string) {
    this.manager.get(id);
  }
  clear () {
    const instances = this.manager.getAll();
    for (const instance of instances) {
      this.delete(instance);
    }
  }
  has (id: string) {
    return this.manager.has(id);
  }
}